/* eslint-disable */
<template>
  <el-container class='home_container' >
    <el-header>
      <div>
        <img alt='' src='../assets/heima.png' />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="danger" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>

      <el-aside :width="isCollapse ? '44px':'200px'"  background-color='#37d4'>
        <div class='toggle-button' @click='toggleCollapse'>|||</div>
        <el-menu :collapse='isCollapse'
                 只允许展开一个
                 unique-opened
                 background-color='#37d4'
                 :router="true"
                 :default-active="activePath">

          <el-submenu :index="item.id+'' " v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class='iconsObj[item.id]'></i>
              <span>{{ item.authName }}</span>
            </template>

              <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState('/'+subItem.path)">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span> {{ subItem.authName }}</span>
                </template>
              </el-menu-item>
          </el-submenu>
          </el-menu>
      </el-aside>

      <el-main>
        <router-view></router-view>
      </el-main>

    </el-container>
  </el-container>
</template>

<script>
   export default {
  name: 'Home',
  data(){
    return{
      isCollapse: false,
      menuList:[],
      activePath:'',
      iconsObj: {
        125: 'el-icon-s-custom',
        103: 'el-icon-s-check',
        101: 'el-icon-s-goods',
        102: 'el-icon-s-order',
        145: 'el-icon-s-marketing'
      },
    }
  },
     created() {
    this.getMenuList()
       this.activePath = window.sessionStorage.getItem('activePath')
       let activePath;
       this.activePath = activePath
     },
     methods:{
    logout(){
      window.sessionStorage.clear()
      this.$router.push('/login')
      this.$message.warning('已退出')
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
        async getMenuList(){
          // eslint-disable-next-line no-unused-vars
      const {data:res} = await this.$http.get('menus')
          if(res.meta.status !==200)return this.$message.error(res.meta.msg)
          this.menuList = res.data
       },
       saveNavState(activePath) {
         window.sessionStorage.setItem('activePath', activePath)
         this.activePath = activePath
       }

  }
}
</script>


<style scoped>
el-submenu{
  padding-right:10px
}
.home_container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.el-header > div {
  display: flex;
  align-items: center;
}
.el-header > div > span {
  margin-left: 15px;
}
.toggle-button {
  background-color:#37d4;
  font-size: 10px;
  line-height: 24px;
  color: rgb(144, 147, 153);
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer
}
</style>
